package com.yxe.controller;

import com.yxe.api.CommonResult;
import com.yxe.pojo.Collection;
import com.yxe.pojo.House;
import com.yxe.service.CollectionService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yang
 * @since 2022-12-08
 */
@RestController
@RequestMapping("collection")
@Api(tags = "收藏模块")
public class CollectionController {

    @Resource
    private CollectionService collectionService;

    /**
     * 添加收藏
     * @param collection
     */
    @GetMapping("insertCollection")
    public String insertCollection(Collection collection){
        collectionService.insertCollection(collection);
        return "success";
    }

    /**
     * 取消收藏
     * @param id
     * @return
     */
    @PostMapping("deleteCollection")
    public String deleteCollection(Integer id){
        collectionService.deleteCollection(id);
        return "success";
    }

    @GetMapping("findAll")
    public CommonResult<House> findAll(Integer userId){

        List<House> houseList = collectionService.findAll(userId);

        CommonResult commonResult = CommonResult.success(houseList);
        commonResult.setData(houseList);

        return commonResult;
    }
}
